<?
class ManageChief extends Module
{
	function ManageChief($row)
	{
		Module::Module($row);
        $hotel_ids = '';
		

        
		switch (Url::get('cmd'))
		{
            case 'gpm':
                if(User::have_permit('hotel_edit') || $hotel_ids != '')
                {
                    CGlobal::$website_title = "Phân quyền quản lý Khách sạn";
                    
                    require_once "forms/BoothPermission.php";
		            $this->add_form(new BoothPermissionForm);
                }
                else
                {
                    Url::redirect_current();
                }
                
                break;
            case 'edit':
                if(User::have_permit('hotel_edit') || $hotel_ids != '')
                {
                    CGlobal::$website_title = "Sửa đầu bếp";
                    
                    require_once "forms/ManageChiefEdit.php";
                    $this->add_form(new ManageChiefEditForm);
                }
                else
                {
                    Url::redirect_current();
                }
                
                break;
            case 'add':
                if(User::have_permit('hotel_add'))
                {
                    CGlobal::$website_title = "Thêm đầu bếp";
                    
                    require_once "forms/ManageChiefAdd.php";
                    $this->add_form(new ManageChiefAddForm);
                }
                else
                {
                    Url::redirect_current();
                }
                break;
                
            case 'delete':
          		$id = Url::getInt('id', 0);
                
                if($id)
                {
                	$hotel = Db_Chief::getChiefById($id);
                	
	                if($hotel && $hotel['status'] != -1 && User::have_permit("hotel_delete"))
                	{
	                	Db_Chief::delBoothById($id);
	                }
                }
                
                $href = Url::get('href');
                
                if($href)
                {
                	Url::redirect_url($href);
                }
                else 
                {
                	Url::redirect_current(array('hotel_id'));
                }
                break;
                
            case 'show':
                $status=1;
                
            case 'hide':
                if(!isset($status))
                {
                    $status		=	2;
                }
                
                $id = Url::getInt('id', 0);
                
                $href = Url::get('href');
                
                if($id)
                {
                    $hotel = Db_Chief::getChiefById($id);

                    if($hotel && $hotel['status'] != -1 && $hotel['status'] != $status && (User::have_permit("hotel_edit") || Db_Hotel::have_permit_manage($hotel, User::id())))
                	{
                        Db_Chief::update(array("status" => $status),$id);
                	}
                }
                
                $href = Url::get('href');
                
                if($href != "")
                {
                	Url::redirect_url($href);
                }
                else 
                {
                	Url::redirect_current(array('hotel_id'));
                }
                
                break;
            case 'restore':
                $id = Url::getInt('id', 0);
                
                if($id)
                {
                    $hotel = Db_Chief::getChiefById($id);

                    if($hotel && $hotel['status'] == -1 && User::have_permit("hotel_edit"))
                	{
                        Db_Chief::update(array("status" => 1),$id);
                	}
                }
                
                $href = Url::get('href');
                
                if($href)
                {
                	Url::redirect_url($href);
                }
                else 
                {
                	Url::redirect_current(array('hotel_id'));
                }
                
                break;   
            default:
                CGlobal::$website_title = "Quản trị đầu bếp";
                
                require_once "forms/ManageChief.php";
                $this->add_form(new ManageChiefForm());
                
                break;
        }
	}
	
	static function permission()
	{
        return array(
                    //'hotel_admin' 	=> "Quản lý Khách sạn",
                    'hotel_delete' 	=> "Xóa Hotel",
                    'hotel_add'    	=> "Thêm Hotel",
                    'hotel_edit'   	=> "Sửa Hotel",
                    'hotel_list'   	=> "List Hotel"
                );
    }
}
?>